/*
 * @Description: 显示模块任务管理
 * @Author: Sang Hao
 * @Date: 2021-09-15 17:06:34
 * @LastEditTime: 2021-11-10 16:48:47
 * @LastEditors: Sang Hao
 */
#ifndef LIDAR_SLAM_MAPPING_VIEWER_VIERER_FLOW_HPP_
#define LIDAR_SLAM_MAPPING_VIEWER_VIERER_FLOW_HPP_

#include <deque>
#include <ros/ros.h>

/*subscriber*/
#include "lidar_slam/subscriber/cloud_subscriber.hpp"
#include "lidar_slam/subscriber/odometry_subscriber.hpp"
#include "lidar_slam/subscriber/key_frame_subscriber.hpp"
#include "lidar_slam/subscriber/key_frames_subscriber.hpp"

/* publisher */
#include "lidar_slam/publisher/odometry_publisher.hpp"
#include "lidar_slam/publisher/cloud_publisher.hpp"

/* viewer */
#include "lidar_slam/mapping/viewer/viewer.hpp"

namespace lidar_slam {
class ViewerFlow {
private:
	/* data */
	/* subscriber */
	std::shared_ptr<CloudSubscriber> cloud_sub_ptr_;
	std::shared_ptr<OdometrySubscriber> transformed_odom_sub_ptr_;
	std::shared_ptr<KeyFrameSubscriber> key_frame_sub_ptr_;
	std::shared_ptr<KeyFramesSubscriber> optimized_key_frames_sub_ptr_;
	
	/* publisher */
	std::shared_ptr<OdometryPublisher> optimized_odom_pub_ptr_;
	std::shared_ptr<CloudPublisher> current_scan_pub_ptr_;
	std::shared_ptr<CloudPublisher> global_map_pub_ptr_;
	std::shared_ptr<CloudPublisher> local_map_pub_ptr_;

	/* segmentation */
	std::shared_ptr<CloudPublisher> seged_map_pub_ptr_;

	/* viewer*/
	std::shared_ptr<Viewer> viewer_ptr_;

	std::deque<CloudData> cloud_data_buff_;
	std::deque<PoseData> transformed_odom_buff_;
	std::deque<KeyFrame> key_frame_buff_;
	std::deque<KeyFrame> optimized_key_frames_;
	std::deque<KeyFrame> all_key_frames_;

	/* sensor data */
	CloudData current_cloud_data_;
	PoseData current_transformed_odom_;

/* 私有函数 */
private:
	bool ReadData();
	bool HasData();
	bool ValidData();
	bool PublishGlobalData();
	bool PublishLocalData();

/* 公有函数，保留的对外接口 */
public:
	ViewerFlow(ros::NodeHandle& nh);

	bool Run();
	bool SaveMap();
	bool PublishGlobalSegData();
};
}

#endif